﻿CREATE TABLE [dbo].[DataMapping] (
	[DataMappingId]			BIGINT	NOT NULL IDENTITY,
    [RuleId]            INT             NOT NULL,
    [SourceDataId] BIGINT          NOT NULL,
    [TargetDataId] BIGINT          NOT NULL,
	[TransformationDataId] BIGINT          NULL,
    [TransformationId]         SMALLINT        NOT NULL,
	[BusinessRules]	NVARCHAR(2500) NULL,
    [ErrorHandling]     NVARCHAR (2500) NULL,
	[Comments]       NVARCHAR (2500) NULL,
    CONSTRAINT [FK_DataMapping_SourceData] FOREIGN KEY ([SourceDataId]) REFERENCES [dbo].[Data] ([DataId]),
    CONSTRAINT [FK_DataMapping_TargetData] FOREIGN KEY ([TargetDataId]) REFERENCES [dbo].[Data] ([DataId]),
	CONSTRAINT [FK_DataMapping_TransformationData] FOREIGN KEY ([TransformationDataId]) REFERENCES [dbo].[Data]([DataId]),
    CONSTRAINT [FK_DataMapping_Rule] FOREIGN KEY ([RuleId]) REFERENCES [dbo].[Rule] ([RuleId]), 
    CONSTRAINT [FK_DataMapping_Transformation] FOREIGN KEY ([TransformationId]) REFERENCES [dbo].[Transformation]([TransformationId]), 
    CONSTRAINT [PK_DataMapping] PRIMARY KEY ([DataMappingId])
     
);

